package jjn.round1;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiang Jining
 * @since 2023-01-17 23:44
 */
public class LeetCode1814_CountNicePairsInAnArray {
    public int countNicePairs(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        int total = 0;
        for (int num : nums) {
            int res = num - reverse(num);
            Integer count = map.getOrDefault(res, 0);
            total += count;
            total = total % (int) (1e9 + 7);
            count++;
            map.put(res, count);
        }
        return total;
    }
    
    private int reverse(int num) {
        int result = 0;
        while (num > 0) {
            result = result * 10 + num % 10;
            num = num / 10;
        }
        return result;
    }
}
